package com.haoshuang.zhouzhoubang.ui.dialog

import android.content.Context

import android.widget.CheckBox

import android.widget.TextView
import com.haoshuang.zhouzhoubang.R
import com.haoshuang.zhouzhoubang.config.URLConstants
import com.haoshuang.zhouzhoubang.ui.page.help.detail.HelpDetailActivity


import com.lxj.xpopup.core.BottomPopupView
import com.mufeng.libs.utils.SpannableStringUtils
import com.mufeng.libs.utils.startPage
import com.mufeng.libs.utils.toast
import com.mufeng.libs.utils.view.visibleOrGone


class QdDialog2(
    context: Context,
    phone: String,
    val money: String? = null,
    private val onSubmit: () -> Unit
) : BottomPopupView(context) {
    override fun getImplLayoutId(): Int = R.layout.dialog_tis4
    var phone2 = phone
    override fun initPopupContent() {
        super.initPopupContent()


        var tvPrice = findViewById<TextView>(R.id.tvPrice)
        var tvGb2 = findViewById<TextView>(R.id.tvGb)
        var checkboxTextView = findViewById<TextView>(R.id.checkboxText)
        var checkbox = findViewById<CheckBox>(R.id.checkbox)
        val tvBaoXianFee = findViewById<TextView>(R.id.tvBaoXianFee)
        val content1 = context?.let {
            SpannableStringUtils(it, "我已阅读并同意《服务保障》和《师傅订单服务协议》")
                .first("我已阅读并同意")
                .onClick(checkboxTextView) {
                    checkbox.isChecked = !checkbox.isChecked
                }
                .first("《服务保障》")
                .textColor(R.color.c_3b76c2)
                .onClick(checkboxTextView) {
                    var url = "${URLConstants.baseUrl}/index/index/agreement?id=5"
                    context.startPage<HelpDetailActivity>("title" to "服务保障", "url" to url)
                }
                .first("《师傅订单服务协议》")
                .textColor(R.color.c_3b76c2)
                .onClick(checkboxTextView) {
                    var url = "${URLConstants.baseUrl}/index/index/agreement?id=6"
                    context.startPage<HelpDetailActivity>(
                        "title" to "师傅订单服务协议",
                        "url" to url
                    )
                }
        }
        checkboxTextView.text = content1
        tvPrice.text = phone2

        tvBaoXianFee.visibleOrGone(money != null)
        tvBaoXianFee.text = "服务完成后需从服务费中扣除${money}元保险意外险"


        var tvCommit = findViewById<TextView>(R.id.tvCommit)

        tvGb2.setOnClickListener {

            dismiss()
        }
        tvCommit.setOnClickListener {

            if (!checkbox.isChecked) {
                toast("请勾选服务保证协议")
                return@setOnClickListener
            }
            dismiss()
            onSubmit()
        }
    }


}